package com.tensai.study.新概念.响应式编程.reactor;

import reactor.core.publisher.Flux;

import java.util.Objects;

/**
 * @author Tensai
 */
public class FluxTest {

    public static void main(String[] args) {
        range();
        err();
    }

    private static void range(){
        Flux.range(1, 100)
                .timeout(Flux.never(), v -> Flux.never())
                .subscribe(item->{
                    try {
                        Thread.sleep(200);
                        System.out.println(item);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                });
    }

    private static void err(){
        Flux.range(1, 10)
                // 过滤
                .map(item -> {
                    // 偶数翻倍
                    if(item == 7) { // 到7进行异常抛出
                        throw new RuntimeException();
                    }
                    return item;
                })
                // 消费
                .subscribe(item -> System.out.print(item + " "), info -> System.out.print("异常"),
                        () -> System.out.println("完成"));
// 1 2 3 4 5 6 异常

    }
}
